package edu.ynu.se.xiecheng.achitectureclass.dao;

import edu.ynu.se.xiecheng.achitectureclass.entity.SensorData;
import edu.ynu.se.xiecheng.achitectureclass.entity.Device;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Repository
public interface SensorDataRepository extends JpaRepository<SensorData, Long> {
    @Query("SELECT s FROM SensorData s WHERE s.createTime = (SELECT MAX(s2.createTime) FROM SensorData s2)")
    Optional<SensorData> findLatestSensorData();
    
    List<SensorData> findByCreateTimeBetween(LocalDateTime start, LocalDateTime end);
    List<SensorData> findByDeviceAndCreateTimeBetween(Device device, LocalDateTime start, LocalDateTime end);
} 